using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Web;
using System.Collections.Specialized;
using DapperDB.Dal;

namespace DapperDB.Entities
{

    public partial class Task_JobDap : BaseDap
    {
        public Task_JobDap()
        {
        }

        public Task_JobDap(IDbConnection connection)
        {
            Connection = connection;
        }

        public Task_JobDap(IDbTransaction transaction)
        {
            Transaction = transaction;
            Connection = transaction.Connection;
        }

        public Task_JobDap(BaseDap dapProvider)
        {
            Transaction = dapProvider.Transaction;
            Connection = dapProvider.Connection;
        }

        public List<Task_Job> GetTop(int count)
        {
            return Query<Task_Job>(string.Format("SELECT TOP {0} * FROM {1}", count, SqlTableName)).ToList();
        }
        public List<Task_Job> GetAll()
        {
            return Query<Task_Job>(string.Format("SELECT * FROM {0} order by createtime asc", SqlTableName)).ToList();
        }

        public Task_Job GetByID(Int32 ID)
        {
            return Query<Task_Job>(SqlSelectCommand + " WHERE StoreId=@StoreId", new { ID = ID }).FirstOrDefault();
        }

        public void Insert(Task_Job model)
        {
            Execute(SqlInsertCommand, model);
        }



        public void Insert(IEnumerable<Task_Job> models)
        {
            Execute(SqlInsertCommand, models);
        }

        public void Delete(string ID)
        {
            Execute(SqlDeleteCommand, new { ID = ID });
        }

        public void Update(Task_Job model)
        {
            Execute(SqlUpdateCommand, model);
        }

        public void DeleteExt(string ID)
        {
            Int32 key = Convert.ToInt32(ID);
            Execute(SqlDeleteCommand, new { ID = key });
        }

        public void DeleteExtBat(string pkNameArr)
        {
            Execute(SqlDeleteCommandBat + "  where ID in (" + pkNameArr + ")");

        }

        public Task_Job GetByKey(string ID)
        {
            return Query<Task_Job>(SqlSelectCommand + " WHERE ID=@ID", new { ID = ID }).FirstOrDefault();

        }

        public void Update(IEnumerable<Task_Job> models)
        {
            IEnumerator iEnumerator = models.GetEnumerator();
            StringBuilder sb = new StringBuilder();
            while (iEnumerator.MoveNext())
            {
                Task_Job cur = (Task_Job)iEnumerator.Current;
                string keyid = cur.ID;
                sb.Append(keyid);
            }
            Execute(SqlUpdateCommand, models);
        }

        public const string SqlTableName = "Task_Job";
        public const string SqlSelectCommand = "SELECT * FROM " + SqlTableName;
        public const string SqlInsertCommand = "INSERT INTO " + SqlTableName + " ( ID ,Job_ServiceName,Job_DllPath,Job_State,Job_Name ,Job_Group ,Trigger_Name ,Trigger_Group ,SetUpTime ,FunctionCount ,LastTime ,ProcessTime ,NextTime ,CreateTime  ) VALUES ( @ID ,@Job_ServiceName,@Job_DllPath,@Job_State,@Job_Name ,@Job_Group ,@Trigger_Name ,@Trigger_Group ,@SetUpTime ,@FunctionCount ,@LastTime ,@ProcessTime ,@NextTime ,@CreateTime  ) ";
        public const string SqlUpdateCommand = "UPDATE " + SqlTableName + " SET ID= @ID ,Job_ServiceName=@Job_ServiceName,Job_DllPath=@Job_DllPath,Job_Name= @Job_Name ,Job_Group= @Job_Group ,Trigger_Name= @Trigger_Name ,Trigger_Group= @Trigger_Group ,SetUpTime= @SetUpTime ,Job_State=@Job_State,FunctionCount= @FunctionCount ,LastTime= @LastTime ,ProcessTime= @ProcessTime ,NextTime= @NextTime ,CreateTime= @CreateTime  WHERE ID=@ID";
        public const string SqlDeleteCommand = "DELETE FROM " + SqlTableName + " WHERE ID=@ID";
        public const string SqlDeleteCommandBat = "DELETE FROM " + SqlTableName;


    }

}
